<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="邵铭">
    <title></title>
    <style>
        * {
            box-sizing: border-box;
        }
        
        .box {
            width: 790px;
            height: 340px;
            margin: 100px auto;
            position: relative;
        }
        
        ul {
            margin: 0;
            padding: 0;
            list-style: none;
        }
        
        .img-list li {
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }
        
        .img-list li.current {
            display: block;
        }
        
        .indicator {
            width: 100%;
            position: absolute;
            left: 0;
            bottom: 20px;
            display: flex;
            justify-content: center;
        }
 .indicator li.active {
            background-color: red;
            cursor: pointer;
        }
        
        .indicator li {
            width: 15px;
            height: 15px;
            background-color: rgba(255, 255, 255, 0.2);
            text-align: center;
            border-radius: 50%;
            cursor: pointer;
            margin: 0 5px;
        }
        
        .img-click span {
            width: 30px;
            height: 40px;
            line-height: 40px;
            color: white;
            position: absolute;
            background-color: rgba(0, 0, 0, 0.1);
            top: calc(50% - 20px);
            display: none;
            font-size: 20px;
            text-align: center;
        }
        
        .img-click .prev {
            left: 0;
        }
        
        .img-click .next {
            right: 0;
        }
        
        .img-click span:hover {
            background-color: #333;
        }
    </style>
</head>

<body>

    <div class="box">
        <ul class="img-list">
            <li class="current">
                <a href="#"><img src="1.jpg" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="2.jpg" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="3.jpg" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="4.jpg" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="5.jpg" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="6.jpg" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="7.jpg" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="8.jpg" alt=""></a>
            </li>
        </ul>
        <ul class="indicator">
            <li class="active"></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
        <div class="img-click">
            <span class="prev">&lt;</span>
            <span class="next">&gt;</span>
        </div>
    </div>
    <script src="./jquery.js"></script>
</body>

</html>
<script>
var index = 0;
    //上一张
    function prevImg() {
        index = index == 0 ? $('.img-list li').length - 1 : index - 1;
        showImg();
    }
    //下一张
    function nextImg() {
        index = index == $('.img-list li').length - 1 ? 0 : index + 1;
        showImg();
    }
    // 展示图片
    function showImg() {
        $('.img-list li').eq(index).addClass('current').siblings().removeClass('current');
        $('.indicator li').eq(index).addClass('active').siblings().removeClass('active');
    }
    // 自动切换图片
    var timer = setInterval(nextImg, 1000);
    // 根据指示灯切换图片
    $('.indicator li').each(function () {
        $(this).hover(function () {
            clearInterval(timer);
            index = $(this).index();
            showImg();
        }, function () {
            timer = setInterval(nextImg, 1000);
        })
    });

    // 点击按钮切换图片
    $('.box').hover(function(){
        clearInterval(timer);
        timer = null;
        $('.prev').show();
        $('.next').show();
    },function(){
        if(timer) return;
        timer = setInterval(nextImg,1000);
        $('.prev').hide();
        $('.next').hide();
    })
    $('.prev').click(function(){
        prevImg();
    });
    $('.next').click(function(){
        nextImg();
    });


</script>